package com.xbe.visibility.controller;

import com.xbe.common.core.controller.BaseController;
import com.xbe.common.utils.DateUtils;
import com.xbe.visibility.domain.Visibility;
import com.xbe.visibility.service.IVisibilityService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * 能见度Controller
 *
 * @author ruoyi
 * @date 2020-08-13
 */
@Controller
@RequestMapping("/visibility/visibility")
public class VisibilityController extends BaseController
{
    private String prefix = "visibility/visibility";

    @Autowired
    private IVisibilityService visibilityService;

    @RequiresPermissions("visibility:visibility:view")
    @GetMapping("/query/{sim}")
    public String visibility(@PathVariable("sim") String sim, ModelMap map)
    {
        map.put("sim", sim);
        return prefix + "/visibility";
    }

    /**
     * 查询能见度数据
     */
    @GetMapping("/list/{startTime}/{endTime}/{sim}")
    @ResponseBody
    public List list(@PathVariable String startTime, @PathVariable String endTime,
                     @PathVariable String sim)
    {


        List<Visibility> visibilities = visibilityService.selectVisibilityList(startTime, endTime
                , sim);


        List x_List = new ArrayList();
        List y_List = new ArrayList();
        List returnList = new ArrayList();
        for (Visibility visibility : visibilities)
        {

            x_List.add(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm", visibility.getCreateTime()));
            y_List.add(visibility.getSeeing().intValue());

        }
        returnList.add(x_List);
        returnList.add(y_List);


        return returnList;


    }


    //定时删除数据

    public void removeData(Integer days)
    {
        visibilityService.removeData(days);
    }


}
